package games.checkers;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class checkersControls extends JPanel implements ActionListener
{
	private checkers program;
	private Dimension dim;
	private JComboBox huffingSet;
	private JComboBox chooseColors;
	private JComboBox numberPlayers;
	private JComboBox gameLevels;
	
	public checkersControls(checkers p)
	{
		program = p;
		dim = new Dimension(512,64);
		setSize(dim);
		setPreferredSize(dim);
		//Color bgColor = new Color(139,69,19);
		Color bgColor = new Color(160,82,45);
		setBackground(bgColor);
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JPanel optionsPanel = new JPanel();
		optionsPanel.setBackground(bgColor);
		
		JPanel buttonsPanel = new JPanel();
		buttonsPanel.setBackground(bgColor);
		
		Color toolColor = new Color(240,255,240);//220,220,220
		//set up the options
		huffingSet = new JComboBox(new String [] {"Huffing On","Huffing Off"});
		huffingSet.setActionCommand("huffingSet");
		huffingSet.addActionListener(this);
		huffingSet.setBackground(toolColor);
		optionsPanel.add(huffingSet);
		
//		chooseColors = new JComboBox(new String [] {"Green & Buff","Black & Red","Black & White"});
//		chooseColors.setActionCommand("chooseColors");
//		chooseColors.addActionListener(this);
//		chooseColors.setBackground(toolColor);
//		optionsPanel.add(chooseColors);
		
		numberPlayers = new JComboBox(new String [] {"1 Player","2 Players"});
		numberPlayers.setSelectedIndex(0);
		numberPlayers.setActionCommand("numberPlayers");
		numberPlayers.addActionListener(this);
		numberPlayers.setBackground(toolColor);
		optionsPanel.add(numberPlayers);
		
		gameLevels = new JComboBox(new String [] {"Easy","Normal","Hard"});
		gameLevels.setSelectedIndex(1);
		gameLevels.setActionCommand("gameLevels");
		gameLevels.addActionListener(this);
		gameLevels.setBackground(toolColor);
		optionsPanel.add(gameLevels);
		
		// set up the buttons
		JButton newGame = new JButton("New Game");
		newGame.setActionCommand("newGame");
		newGame.addActionListener(this);
		buttonsPanel.add(newGame);
		newGame.setBackground(toolColor);
		
		JButton about = new JButton("About");
		about.setActionCommand("About");
		about.addActionListener(this);
		about.setBackground(toolColor);
		buttonsPanel.add(about);
		
		JButton suggest = new JButton("Suggest");
		suggest.setActionCommand("Suggest");
		suggest.addActionListener(this);
		suggest.setBackground(toolColor);
		buttonsPanel.add(suggest);
		
		add(optionsPanel);
		add(buttonsPanel);
	}

	@Override
	public void actionPerformed(ActionEvent action) 
	{
		 if ("huffingSet".equals(action.getActionCommand())) program.chipManager().huffing(huffingSet.getSelectedIndex());
		 if ("chooseColors".equals(action.getActionCommand())) program.setColorScheme(chooseColors.getSelectedIndex());
		 if ("numberPlayers".equals(action.getActionCommand())) program.numberPlayers(numberPlayers.getSelectedIndex());
		 if ("gameLevels".equals(action.getActionCommand())) program.gameLevel(gameLevels.getSelectedIndex());
		 if ("newGame".equals(action.getActionCommand())) program.newGame();
		 if ("About".equals(action.getActionCommand())) about();
		 if ("Suggest".equals(action.getActionCommand()))program.chipManager().suggest();
	}
	
	private void about()
	{
		String message = "Checkers\nAuthor: Chris Davis\nClass: CS 580\nDue: 05/10/2011";
		JOptionPane.showMessageDialog(this, message, "About", JOptionPane.PLAIN_MESSAGE);
	}
}
